package com.ionehe.group.common.notify.configure;

import com.ionehe.group.common.notify.autoconfigure.AsyncVendors;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

/**
 * Copyright (c) 2021 ionehe.com
 * Date: 2021/4/21
 * Time: 1:22 下午
 *
 * @author 2021年 <a href="mailto:a@ionehe.com">秀</a>
 * 【通知配置类】
 */
@ConfigurationProperties(prefix = "notify", ignoreInvalidFields = true)
@Data
public class NotifyConfiguration implements Cloneable {
    public static final String PREFIX = "notify";
    private Map<String, String> topics;
    private AsyncVendors vendor;
    private Map<AsyncVendors, Map> vendors = new HashMap<>(0);

    @Override
    protected NotifyConfiguration clone() throws CloneNotSupportedException {
        NotifyConfiguration configuration = new NotifyConfiguration();
        Map<String, String> localTopics = (null != this.topics && this.topics.size() > 0) ? new HashMap<>(this.topics) : new HashMap<>(0);
        configuration.setTopics(localTopics);
        configuration.setVendor(this.vendor);
        Map<AsyncVendors, Map> map = new HashMap<>((AsyncVendors.values()).length);
        if (null != this.vendors) {
            for (AsyncVendors k : this.vendors.keySet()) {
                map.put(k, new HashMap<>(this.vendors.get(k)));
            }
        }
        configuration.setVendors(map);
        return configuration;
    }


}
